<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace addons\video\model;


/**
 * 视频付费记录表
 * Class VideoPay  lsj
 * @package addons\video\model
 */
class VideoPay extends \web\common\model\BaseModel{
    
    protected function _initialize(){
        $this->tableName = 'video_pay';
    }

    /**
     * 创建视频购买记录
     * @param $user_id
     * @param $video_id
     * @param $price
     * @param int $end_number
     * @return \web\common\model\type
     */
    public function addData($user_id, $video_id, $price, $end_number = 9999){
        $add_data = [
            'user_id' => $user_id,
            'video_id' => $video_id,
            'price' => $price,
            'create_time' => NOW_DATETIME,
            'end_time' => date("Y-m-d H:i:d", (time() + ($end_number * 86400))),
        ];
        return $this->add($add_data);
    }

    public function getUserLikeList($pageIndex = -1, $pageSize = -1, $filter = '',$fileds='*', $order = 'id desc') {
        $sql = 'select '.$fileds.' from '.$this->getTableName() . ' as a right join tp_video as v ON v.id=a.video_id left join tp_member_account as m ON m.id=v.user_id  where 1=1 '.$filter;
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }

    /**
     * 关联分类表列表
     * @param int $pageIndex
     * @param int $pageSize
     * @param string $filter
     * @param string $fields
     * @param string $order
     * @return mixed
     */
    public function getVideoPayList($pageIndex = -1, $pageSize = -1, $filter = '', $fields = 'a.*', $order = 'order_index asc') {
        $sql = 'select '.$fields.' from ' . $this->getTableName().' as a left join tp_video as b on b.id=a.video_id left join tp_member_account as m on m.id=a.user_id ' ;
        if (!empty($filter))
            $sql .= ' where ' . $filter;
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }


}
